Skip to content

Conversation

@jmagman
Copy link
Member

@jmagman jmagman commented Aug 14, 2025

Seen when upgrading to Xcode 26.

Introduced in #8311.

Fixes flutter/flutter#173744

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly removes an explicit type specialization in a Swift map call to resolve a compiler warning. I've added a couple of suggestions. One is to correct the CHANGELOG entry, as the change affects the plugin's source code, not the example app. The other, more critical suggestion is to replace try! with try on the modified line to prevent a potential runtime crash and properly propagate errors, aligning with the function's throwing signature.

let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar

let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> {
let keyValueTuples = try! properties.map {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using try! can cause a crash if the map operation throws an error. The closure can throw an error, for example, for an unknown enum case or when sameSitePolicy is used on an older OS version. Since the pigeonDefaultConstructor function is marked with throws, the error should be propagated with try instead of try! to prevent a potential crash.

Suggested change
let keyValueTuples = try! properties.map {
let keyValueTuples = try properties.map {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a Swift expert, @hellohuanlin what's the idiomatic thing to do here? And is that correct in the context of this plugin?
There are no warnings without the !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the caller:

do {
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
try api.pigeonDelegate.pigeonDefaultConstructor(pigeonApi: api, url: urlArg),
withIdentifier: pigeonIdentifierArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))

It wraps pigeonDefaultConstructor call under a do/catch block, and if it throws, it replies error to the dart side.

So if you use try here, when it throws, it will be eventually propagated to dart side;
If you use try! here, when it throws, it will crash.

Given that this code is setup this way (throwable method + do/try/catch block), I'd say the expected usage is not to crash. So let's go with try.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar

let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> {
let keyValueTuples = try! properties.map {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was complaining because line 13 above in the function declaration already contains the type information [HttpCookiePropertyKey: Any]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! The old rule is that yon can always explicitly provide types, and what's more, sometimes you must explicitly provide types for super long statements where swift compiler fails auto-infer the types).

@jmagman jmagman changed the title [webview_flutter_wkwebview] Remove specialization of 'map' in example app to fix Swift warning [webview_flutter_wkwebview] Remove specialization of 'map' to fix Swift warning Aug 14, 2025
@jmagman jmagman marked this pull request as ready for review August 14, 2025 18:09
@jmagman jmagman requested a review from LouiseHsu as a code owner August 14, 2025 18:09
@jmagman jmagman requested a review from hellohuanlin August 14, 2025 18:09
let registrar = pigeonApi.pigeonRegistrar as! ProxyAPIRegistrar

let keyValueTuples = try! properties.map<[(HTTPCookiePropertyKey, Any)], PigeonError> {
let keyValueTuples = try properties.map {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't i review this PR before? gosh my memory is getting messed up!

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 16, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 16, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 16, 2025

autosubmit label was removed for flutter/packages/9810, because - The status or check suite Mac_arm64 ios_platform_tests_shard_1 master has failed. Please fix the issues identified (or deflake) before re-applying this label.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Sep 24, 2025

autosubmit label was removed for flutter/packages/9810, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2025
@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 30, 2025
@auto-submit auto-submit bot merged commit 5fc2fd7 into flutter:main Oct 30, 2025
80 checks passed
@jmagman jmagman deleted the specialize-map branch October 30, 2025 23:02
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 4, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Nov 4, 2025
flutter/packages@1a7075b...3d926aa

2025-11-04 49699333+dependabot[bot]@users.noreply.github.com
[dependabot]: Bump com.squareup.okhttp3:okhttp from 5.1.0 to 5.3.0 in
/packages/espresso/android (flutter/packages#10348)
2025-11-04 engine-flutter-autoroll@skia.org Roll Flutter from
6f8abdd to 027f2e4 (26 revisions) (flutter/packages#10335)
2025-11-03 stuartmorgan@google.com [google_sign_in] Remove use of OCMock
(flutter/packages#10290)
2025-11-03 stuartmorgan@google.com [interactive_media_ads] Pin iOS
dependency maximum (flutter/packages#10349)
2025-10-30 magder@google.com [webview_flutter_wkwebview] Remove
specialization of 'map' to fix Swift warning (flutter/packages#9810)
2025-10-30 engine-flutter-autoroll@skia.org Roll Flutter from
df72035 to 6f8abdd (16 revisions) (flutter/packages#10327)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: webview_flutter platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[webview_flutter_wkwebview] HTTPCookieProxyAPIDelegate warning Cannot explicitly specialize instance method 'map'

3 participants